﻿// Learn more about F# at http://fsharp.net
open SmartRoute.Data
open System.Xml.Serialization
open System.Runtime.Serialization

let path = @"U:\dev2\dev\data\Stops.csv"

let lines = System.IO.File.ReadAllLines(path)

let allExceptFirstLine = lines.[1..]

let rows = 
    allExceptFirstLine
    |> Array.map (fun x -> x.Split([|','|]))
    
let ehs = new School("Ellensburg High School","1203 East Capitol Ave.",SchoolType.High,System.DateTime.Now,System.DateTime.Now)

let mms = new School("Morgan Middle School","400 East 1st Ave.",SchoolType.Middle,System.DateTime.Now,System.DateTime.Now)

let mses = new School("Mt. Stuart Elementary School","705 W. 15 Ave.",SchoolType.Elementary,System.DateTime.Now,System.DateTime.Now)

let vves = new School("Valley View Elementary School","1508 E. 3rd Ave.",SchoolType.Elementary,System.DateTime.Now,System.DateTime.Now)

let les = new School("Lincoln Elementary School","200 S. Sampson St.",SchoolType.Elementary,System.DateTime.Now,System.DateTime.Now)

let stopFromRow (a : string array) = 
     let stop = new Stop(a.[8], System.Double.Parse(a.[6]), System.Double.Parse(a.[7]))
     let add sch students = if students = 0 then () else stop.addStudentsHeadedToSchool(sch,students)
     let students = Array.map(System.Int32.Parse)(a.[0..5])
     add ehs  (students.[1])
     add mms  (students.[2])
     add mses (students.[3])
     add vves (students.[4])
     add les  (students.[5])
     stop
     
let stops = Array.map stopFromRow rows

let serializer = new System.Runtime.Serialization.DataContractSerializer(typeof<Stop[]>)

let main = serializer.WriteObject(System.IO.File.OpenWrite(@"U:\dev2\dev\data\Stops.xml"),stops)

main

